var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/table/child/pagination.tsx
var pagination_exports = {};
__export(pagination_exports, {
  TablePagination: () => TablePagination
});
module.exports = __toCommonJS(pagination_exports);
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_react_dom = __toESM(require("react-dom"));
var import_common = require("../base/common");
var import_util = require("../util");
var TablePagination = import_react.default.memo(({ table }) => {
  (0, import_react.useContext)(import_common.DsContext);
  const pageRef = (0, import_react.useRef)();
  const pagination = table.props.pagination ? table.props.pagination === true ? {} : table.props.pagination : { height: 0 };
  const {
    align = "right",
    height = 48,
    leftRender,
    targetContainer = null,
    rightRender,
    onBeforeChange,
    onChange,
    hideOnSinglePage = false,
    ...others
  } = pagination;
  const { pageIndex = 1, pageSize = 15 } = table.state.params;
  const flexStyle = { left: "flex-start", right: "flex-end", center: "center" };
  const [state, setState] = (0, import_react.useState)({ pageIndex, pageSize });
  const [width, setWidth] = (0, import_react.useState)(0);
  const paginationProps = {
    size: "small",
    showSizeChanger: true,
    showQuickJumper: true,
    showLessItems: true,
    hideOnSinglePage,
    total: table.state.total,
    pageSizeOptions: ["15", "30", "100", "500", "1000"],
    showTotal: (total, range) => `第${range[0]}-${range[1]} 条/总共 ${total} 条`,
    onChange: async (pageIndex2, pageSize2) => {
      if (table.state.loading) {
        return;
      }
      if (onBeforeChange) {
        if (await onBeforeChange(pageIndex2, pageSize2) === false) {
          return;
        }
      }
      setState((prev) => ({ ...prev, pageIndex: pageIndex2, pageSize: pageSize2 }));
      table.setExtraParam({ pageIndex: pageIndex2, pageSize: pageSize2, __isPagination__: true });
    },
    style: {
      flexWrap: "nowrap",
      whiteSpace: "nowrap"
    },
    ...others,
    current: state.pageIndex,
    pageSize: state.pageSize
  };
  if (width < 590) {
    paginationProps.showQuickJumper = false;
    if (width < 490) {
      paginationProps.showSizeChanger = false;
    }
    if (width < 300) {
      paginationProps.showTotal = void 0;
    }
    if (width < 200) {
      paginationProps.simple = true;
    }
  }
  const isSinglePage = hideOnSinglePage && table.state.total <= state.pageSize;
  const targetEl = import_util.util.isString(targetContainer) ? document.getElementById(targetContainer) : targetContainer;
  (0, import_react.useEffect)(() => {
    if (pageIndex !== state.pageIndex || pageSize !== state.pageSize) {
      setState({ pageIndex, pageSize });
      onChange == null ? void 0 : onChange(pageIndex, pageSize);
    }
  }, [pageIndex, pageSize]);
  (0, import_react.useEffect)(() => {
    if (!table.state.loading && state.pageIndex > 1 && Math.ceil(table.state.total / state.pageSize) < state.pageIndex) {
      table.setExtraParam({ pageIndex: 1, __isPagination__: true });
    }
  }, [isSinglePage, table.state.total, state.pageIndex, state.pageSize]);
  (0, import_react.useEffect)(() => {
    if (hideOnSinglePage && !targetEl) {
      table._observer.notify({ height: isSinglePage ? 0 : 48 }, "hideOnSinglePage").then();
    }
  }, [isSinglePage, hideOnSinglePage, targetEl]);
  (0, import_react.useEffect)(() => {
    if (!targetEl || !pageRef.current) {
      return;
    }
    if (window.IntersectionObserver) {
      let io = new IntersectionObserver(
        (entries) => {
          if (pageRef.current) {
            if (entries[0].isIntersecting) {
              pageRef.current.style.display = "flex";
            } else {
              pageRef.current.style.display = "none";
            }
          }
        },
        {
          root: table.containerRef.current.parentElement,
          threshold: [0, 1]
        }
      );
      io.observe(table.containerRef.current);
      return () => {
        io.disconnect();
        io = null;
      };
    }
  }, [targetEl, pageRef.current]);
  (0, import_util.useResize)(() => {
    var _a;
    if (height) {
      setWidth(((_a = pageRef.current) == null ? void 0 : _a.offsetWidth) || 0);
    }
  }, pageRef);
  if (!height || isSinglePage) {
    return null;
  }
  const children = /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref: pageRef,
      className: "table-pagination",
      style: {
        display: "flex",
        whiteSpace: "nowrap",
        zIndex: 3,
        background: import_util.cssVar.componentColor,
        height,
        alignItems: "center",
        justifyContent: flexStyle[align] || align
      }
    },
    leftRender && leftRender({ table }),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Pagination, { ...paginationProps }),
    rightRender && rightRender({ table })
  );
  return targetEl ? import_react_dom.default.createPortal(children, targetEl) : children;
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  TablePagination
});
